﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using BusinessLogic.Controller;

public partial class AjaxPages_ControlLoader_DControl : AjaxPage
{
    private Guid CityId
    {
        get
        {
            if (Request.Params["cid"] != null)
            {
                ddLocality.Visible = true;
                return new Guid(Request.Params["cid"]);
            }
            else
            {
                
                return Guid.Empty;
            }
        }
    }
    private Guid StateID
    {
        get
        {
            if (Request.Params["sid"] != null)
            {
                ddCity.Visible = true;
                return new Guid(Request.Params["sid"]);
            }
            else
            {
               
                return Guid.Empty;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CityId != Guid.Empty)
            BindLocality();
        else if (StateID != Guid.Empty)     
        {
            new CityController().BindCity(ddCity, StateID);
        }
    }

    
    private void BindLocality()
    {
        var data = new LocalityController().GetbyCityID(CityId);
        ddLocality.DataSource = data;
        ddLocality.DataTextField = "LocalityName";
        ddLocality.DataValueField = "LocalityID";
        ddLocality.DataBind();
    }
}